/**
 * Created by xie on 2018/4/8.
 */
angular.module('module.personalcenter')
    .controller('ShareController', ShareController);

ShareController.$inject = ['$scope','$state','$cookies','$rootScope','MainpageService'];

function ShareController($scope, $state,$cookies, $rootScope,MainpageService) {
    var vm = this;
    vm.goArticle=goArticle;
    vm.deleteArticle=deleteArticle;
     vm.user=JSON.parse($cookies.get("userInfo"));


        MainpageService.getArticleByUserid(vm.user.userid).$promise.then(function(data){
            vm.articlelist = data;
            console.log(vm.articlelist);
        },function(err){
            console.log(err)
        });



    function goArticle(article){

        $state.go("atricle",{articleid:article.articleid});
    }

    function deleteArticle(articleid){
        if(confirm("是否删除此分享？"))
        { MainpageService.deleteArticleByid(articleid).$promise.then(function(data){
            request = data;
        },function(err){
            console.log(err)
        });

            MainpageService.deleteCommentByArticleid(articleid).$promise.then(function(data){
                request = data;
            },function(err){
                console.log(err)
            });

            MainpageService.deleteDissByArticleid(articleid).$promise.then(function(data){
                request = data;
            },function(err){
                console.log(err)
            });

            javascript:history.back(-1);
        }
    else javascript:history.back(-1);
    }



}